﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace WebApp.Web.Core.Auth
{
    /// <summary>
    /// 跳过授权检查
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public sealed class IgnoreAuthorizeFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (SessionManage.User == null)
            {
                var backurl = "";
                if (filterContext.HttpContext != null
                    && filterContext.HttpContext.Request != null)
                {
                    backurl = filterContext.HttpContext.Request.RawUrl;
                }

                filterContext.Result = new RedirectResult("~/Member/Login?backurl=" + System.Web.HttpUtility.UrlEncode(backurl));
            }
        }
    }
}
